TS.AdminConsoleCommand( "rpa_forcechange", false, function( ply, cmd, arg )

	local name = arg[1]
	local succ, result = TS.FindPlayerByName( name )
	TS.ErrorMessage( ply, false, succ, result )

	local nametochange = arg[2]

	if( succ ) then

	result:GetTable().CCName = nametochange
	result:SetNWString( "RPName", nametochange )

	result:SaveData( "RPName", nametochange or result:GetRPName() )

	end

end )

TS.AdminConsoleCommand( "rpa_createsent", false, function( ply, cmd, arg )

	local trace = { }
	trace.start = ply:EyePos() - Vector( 0, 0, 30 );
	trace.endpos = trace.start + ply:GetAngles():Forward() * 40;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace )

	local ent = ents.Create( arg[1] )
	ent:SetPos( tr.HitPos )
	ent:Spawn()
	ent:Activate()
	
end )	

TS.AdminConsoleCommand( "rpa_slay", false, function( ply, cmd, arg ) 
 
        local name = arg[1];
        local succ, result = TS.FindPlayerByName( name );
        TS.ErrorMessage( ply, false, succ, result );
        
    if( succ ) then
        
        TS.PrintMessageAll( 3, ply:GetRPName() .. " slayed " .. result:GetRPName() );
        
        result:Slay();
        
    end
 
end )

TS.AdminConsoleCommand( "rpa_setweather", false, function( ply, cmd, arg )

	SetGlobalString("weather", arg[1] )
	
end )	

TS.AdminConsoleCommand( "rpa_day", false, function( ply, cmd, arg )

	if( !storm_active ) then
		SetGlobalString("weather","sunny")
	end
end )

TS.AdminConsoleCommand( "rpa_night", false, function( ply, cmd, arg )

	if( not ply:CanUseCommand() ) then return; end
	if not storm_active then
		SetGlobalString("weather","dark")
	end
end )

TS.AdminConsoleCommand( "rpa_wsadd", false, function( ply, cmd, arg )

	GiveWholesaleItem( arg[1] );
	
end )

TS.AdminConsoleCommand( "rpa_removewsitem", false, function( ply, cmd, arg )

	local x = arg[1]
	local y = arg[2]
	RemoveWholesaleItemAt( x, y );
	ply:PrintMessage( 2, "Removed item at: " .. x .. "," .. y )
	
end )


TS.AdminConsoleCommand( "rpa_cbadd", false, function( ply, cmd, arg )

	GiveContrabandItem( arg[1] );
	
end )


TS.AdminConsoleCommand( "rpa_removecbitem", false, function( ply, cmd, arg )

	local x = arg[1]
	local y = arg[2]
	RemoveContrabandItemAt( x, y );
	ply:PrintMessage( 2, "Removed item at: " .. x .. "," .. y )
	
end )


TS.AdminConsoleCommand( "rpa_ignite", false, function( ply, cmd, arg )

	if( not arg[2] ) then
	ply:PrintMessage( 2, "rpa_ignite <Name> <Time(secs)>" );
	end
	
	local name = arg[1];
	local burntime = tonumber( arg[2] );
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " ignited " .. result:GetRPName() .. " for " .. burntime .. " seconds." );
	
		result:Ignite(burntime,0);
	
	end

end )


TS.AdminConsoleCommand( "rpa_ext", false, function( ply, cmd, arg )

	
	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " extinguished " .. result:GetRPName() );
	
		if ( result:IsOnFire() ) then
		   result:Extinguish()
		end
	
	end

end )


TS.AdminConsoleCommand( "rpa_slap", false, function( ply, cmd, arg )

	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " slapped " .. result:GetRPName() );
	
		local norm = result:GetAngles():Up();
		
		result:SetVelocity( norm * 500 + result:GetAngles():Forward() * math.random( -1000, 1000 ) );
		result:SetHealth( math.Clamp( result:Health() - 5, 1, 1000 ) );
	
	end

end )


TS.AdminConsoleCommand( "rpa_explode", false, function( ply, cmd, arg )

	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " exploded " .. result:GetRPName() );
	
		local exp = ents.Create( "env_explosion" );
			exp:SetKeyValue( "spawnflags", 128 );
			exp:SetPos( result:EyePos() );
		exp:Spawn();
		
		exp:Fire( "explode", "", 0 );
		
		timer.Simple( .2, result.SlaySilent, result );
		
	end

end )


TS.AdminConsoleCommand( "rpa_restartmap", false, function( ply, cmd, arg )
	
	umsg.Start( "ConsoleChat" );
		umsg.String( "Admin " .. ply:GetRPName() .. " (" .. ply:Nick() .. ") is restarting the map"  );
	umsg.End();
	
	timer.Simple( 5, game.ConsoleCommand, "changelevel " .. game.GetMap() .. "\n" );

end )


TS.AdminConsoleCommand( "rpa_boobytrapdoor", false, function( ply, cmd, arg )

	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 4096;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	if( tr.Entity and tr.Entity:IsValid() ) then
	
		if( tr.Entity:IsDoor() ) then
		
			tr.Entity:GetTable().BoobyTrapped = true;
			TS.CreateRedNotify( ply, "Door has been boobytrapped" )
		
		end
	
	end


end )


TS.AdminConsoleCommand( "rpa_findowner", false, function( ply, cmd, arg )

	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 4096;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	if( tr.Entity and tr.Entity:IsValid() ) then
	
		if( tr.Entity:IsDoor() ) then
		
			if( not tr.Entity:GetTable().MainOwner or not tr.Entity:GetTable().MainOwner:IsValid() ) then
			
				ply:PrintMessage( 2, "No one owns this door." );
				return;
			
			end
			
			ply:PrintMessage( 2, tr.Entity:GetTable().MainOwner:GetRPName() .. " (" .. tr.Entity:GetTable().MainOwner:Nick() .. ") " .. "owns this door." );
	
		
		else
		
			ply:PrintMessage( 2, "This isn't a door." );
		
		end
	
	end


end )


TS.AdminConsoleCommand( "rpa_storm", false, function( ply, cmd, arg )

	if not storm_active then
		Console( ply, "Promoted a storm.", true );
		BeginStorm();
	else 
		Console( ply, "A Storm is already in progress!", true );
	end
	
end )


TS.AdminConsoleCommand( "rpa_stopstorm", false, function( ply, cmd, arg )

	
	if( not storm_active ) then
		Console( ply, "There isn't a storm in progress.", true );
	else 
		storm_active = false
		SetGlobalString("weather","sunny")
		Console( ply, "Force stopped storm.", true );
	end
	
end )

TS.AdminConsoleCommand( "rpa_sendpopup", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_sendpopup <Name> <Message Title> <Message> - Send a Pop-up message to a player" );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		Console( ply, "Sent pop-up message to " .. result:GetRPName(), true );
		Console( ply, "Title: " .. arg[2], true );
		Console( ply, "Message: " .. arg[3], true );
		
		umsg.Start( "PPM", result );
			umsg.String( arg[2] );
			umsg.String( arg[3] );
		umsg.End();
		
		
	end

end )


TS.AdminConsoleCommand( "rpa_warn", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_warn <Name> <Message> - Send a warning message to player." );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		Console( ply, "Sent warning message to " .. result:GetRPName(), true );
		Console( ply, "Message: " .. arg[2], true );
		
		umsg.Start( "PPM", result );
			umsg.String( "Warning from admin " .. ply:Nick() .. " (" .. ply:GetRPName() .. ")" );
			umsg.String( arg[2] );
		umsg.End();
		
		
	end

end )


TS.AdminConsoleCommand( "rpa_setmoney", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_setmoney <Name> <Value> - Set a players money" );
		return;
	end
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		result:SetPlayerMoney( arg[2] );
		
		TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your money to " .. arg[2] )
		Console( ply, "Set " .. result:GetRPName() .. "'s money to " .. arg[2], true );
		
		local query = "UPDATE `characters` SET `Tokens` = '" .. arg[2] .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";	
		
		sql.Query( query )
		
		
	end

end )


TS.AdminConsoleCommand( "csay", false, function( ply, cmd, arg )

	if( !ply:EntIndex() == 0 ) then 
		return
	end	

	if( not arg[1] ) then return; end

	local chat = "";
	
	for n = 1, #arg do
		chat = chat .. arg[n] .. " ";
	end

	umsg.Start( "ConsoleChat" );
		umsg.String( chat );
	umsg.End();
	
	TS.PrintMessageAll( 2, "Console: " .. chat );

end )


TS.AdminConsoleCommand( "rpa_candupe", false, function( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_candupe <Name> <1 or 0> - Sets if a player can use the duplicator tool" );
		return;
	end
	
	local name = arg[1];
	local val = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		local bool = true;
		
		if( val == 0 ) then

			bool = false;

			TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") took away your duplicator access" )
			Console( ply, "Took away duplicator access from " .. result:GetRPName(), true );	
			
			local query = "UPDATE `TS2_USERS` SET `CanDupe` = '" .. "no" .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";		
			sql.Query( query )

		else
		
			TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") gave you duplicator access" )
			Console( ply, "Gave duplicator access to " .. result:GetRPName(), true );
			
			local query = "UPDATE `TS2_USERS` SET `CanDupe` = '" .. "yes" .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";		
			sql.Query( query )

			
		end
	
		result:GetTable().CanUseDuplicator = bool;
		
	end


end )


TS.AdminConsoleCommand( "rpa_bring", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_bring <Name> - Bring a player" );
		return;
	end
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
			
		trace = { }
		trace.start = ply:EyePos();
		trace.endpos = trace.start + ply:GetAngles():Forward() * 50;
		trace.filter = ply;
		
		tr = util.TraceLine( trace );

	
		if( tr.Hit ) then

			trace = { }
			trace.start = ply:EyePos();
			trace.endpos = trace.start + ply:GetAngles():Forward() * -50;
			trace.filter = ply;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = ply:EyePos();
			trace.endpos = trace.start + ply:GetAngles():Right() * -50;
			trace.filter = ply;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = ply:EyePos();
			trace.endpos = trace.start + ply:GetAngles():Right() * 50;
			trace.filter = ply;
			
			tr = util.TraceLine( trace );
			
		end
		
		
		result:SetPos( tr.HitPos - Vector( 0, 0, 64 ) );
	
	end

end )


TS.AdminConsoleCommand( "rpa_goto", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_goto <Name> - Go to a player" );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
			
		local trace = { }
		trace.start = result:EyePos();
		trace.endpos = trace.start + result:GetAngles():Up() * 90;
		trace.filter = result;
		
		local tr = util.TraceLine( trace );
	
		if( tr.Hit ) then

			trace = { }
			trace.start = result:EyePos();
			trace.endpos = trace.start + result:GetAngles():Forward() * 50;
			trace.filter = result;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then

			trace = { }
			trace.start = result:EyePos();
			trace.endpos = trace.start + result:GetAngles():Forward() * -50;
			trace.filter = result;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = result:EyePos();
			trace.endpos = trace.start + result:GetAngles():Right() * -50;
			trace.filter = result;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = result:EyePos();
			trace.endpos = trace.start + result:GetAngles():Right() * 50;
			trace.filter = result;
			
			tr = util.TraceLine( trace );
			
		end
		
		
		ply:SetPos( tr.HitPos - Vector( 0, 0, 64 ) );
	
	end

end )


TS.AdminConsoleCommand( "rpa_showmotd", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_showmotd <Name> - Show MOTD to a player" );
		return;
	end
	
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") prompted the MOTD on you", true );
		Console( ply, "Prompted the MOTD on " .. result:GetRPName(), true );
		
		result:PromptMOTD();
	
	end

end )


TS.AdminConsoleCommand( "rpa_yell", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_yell <Text> - Yell at the server angrily" );
		return;
	end
	
	local msg = "";
	
	for n = 1, #arg do
	
		if( msg ~= "" ) then
			msg = msg .. " ";
		end
	
		msg = msg .. arg[n];
	
	end
	
	
	local name;
	
	if( ply:EntIndex() == 0 ) then
		name = "Console";
	else
		name = ply:GetRPName();
	end
	umsg.Start( "Ayell" );
		umsg.String( name .. ": " );
		umsg.String( msg );
	umsg.End();

end )

TS.AdminConsoleCommand( "rpa_ban", false, function( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_ban <Name> <Time> <Reason> - Ban name for time minutes with reason" );
		return;
	end
	
	--if( ply:EntIndex() ~= 0 and not ply:CanUseAdminCommand() ) then return; end
	
	local msg = "";
	
	if( arg[3] ) then
	
		for n = 3, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end
	
	
	local name = arg[1];
	local time = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:Ban( time, msg, ply:GetRPName() );
	
	end
	
end )	
	
TS.AdminConsoleCommand( "rpa_pban", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_pban <Name> <Reason> - Permaban name with reason" );
		return;
	end
		
	local msg = "";
	
	if( arg[2] ) then
	
		for n = 2, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end

	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:PermaBan( msg, ply:GetRPName() );
	
	end

end )


TS.AdminConsoleCommand( "rpa_kick", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_kick <Name> <Reason> - Kick name with reason." );
		return;
	end
	
	
	local msg = "";
	
	if( arg[2] ) then
	
		for n = 2, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:Kick( msg, ply:GetRPName() );
	
	end

end )



TS.AdminConsoleCommand( "rpa_donatormodel", false, function( ply, cmd, arg )
	
	if( not arg[1] or !arg[2] ) then 
		Console( ply, "rpa_donatormodel <name> <modeldirectory>" )
	end
	
	local name = arg[1]
	local model = arg[2]
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( not succ ) then
		succ, result = TS.FindPlayerBySteamID( name );
	end
	
	if( succ ) then
	
		cmd = "UPDATE `characters` SET `Model` = '" .. arg[2] .. "' WHERE `RPName` = '" .. result:GetRPName() .. "'" 
		sql.Query( cmd );
		
		result:SetModel( arg[2] )
		
		TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your model permanently to " .. arg[2] )
		Console( ply, "Set " .. result:GetRPName() .. "s model permanently to " .. arg[2], true )
		
		result:GetTable().CCModel = arg[2]
		result:GetTable().CitizenModel = arg[2]
		
	end

end )

	
TS.AdminConsoleCommand( "rpa_setplayermodel", false, function( ply, cmd, arg )
	
	if( not arg[1] or !arg[2] ) then 
		Console( ply, "rpa_setplayermodel <name> <modeldirectory>" )
	end
		
	local name = arg[1]
	local model = arg[2]
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( not succ ) then
		succ, result = TS.FindPlayerBySteamID( name );
	end
	
	if( succ ) then
	
		result:SetModel( arg[2] )
		
		--Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your model to " .. arg[2], true )
		--Console( ply, "Set " .. result:GetRPName() .. "s model to " .. arg[2], true )
		
		TS.CreateRedNotify( result, "Your model has been set to " .. arg[2] )
		
	end

end )



TS.AdminConsoleCommand( "rpa_givett", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_givett <Name>/<SteamID> - Toggles tool trust on a player" );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( not succ ) then
		succ, result = TS.FindPlayerBySteamID( name );
	end
	
	if( succ ) then
				
		if( !result:HasTT() ) then
		
			result:Give( "gmod_tool" );
			result:GetTable().TT = true;
							
			TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has given you tool trust" )
			Console( ply, "Gave TT to " .. result:GetRPName(), true );
			
			
			cmd = "UPDATE `users` SET `HasToolTrust` = '" .. "advanced" .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'" 
			sql.Query( cmd );
			
		end	
		
		if( result:HasTT() ) then
		
			result:StripWeapon( "gmod_tool" );
			result:GetTable().TT = false;
			
			TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has removed your tool trust" )
			Console( ply, "Removed TT from " .. result:GetRPName(), true );
			
			cmd = "UPDATE `users` SET `HasToolTrust` = '" .. " " .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'" 
			sql.Query( cmd );
		
		end

	end

end )



TS.AdminConsoleCommand( "rpa_oocdelay", false, function( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[1] ) ) then 
		Console( ply, "rpa_oocdelay <Delay> - Set an OOC delay" );
		return;
	end
	
	
	local delay = tonumber( arg[1] );
	
	umsg.Start( "ODC" );
		umsg.String( ply:GetRPName() );
		umsg.Float( delay );
	umsg.End();
	
	for k, v in pairs( player.GetAll() ) do
	
		v:GetTable().NextTimeCanChatOOC = CurTime();
	
	end
	
	TS.PrintMessageAll( 2, "Admin " .. ply:GetRPName() .. " has set the OOC delay to " .. delay ); 
	TS.OOCDelay = delay;
	
end )

TS.AdminConsoleCommand( "rpa_hunter", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_hunter <Name> - Make player hunter" );
		return;
	end

	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		result:SetModel( "models/hunter.mdl" )
		result:SetTeam( 4 )
		result:SetField( "radiofreq", TS.CombineRadioFreq )
		
		if( not result:HasInventory( "Command Armor" ) ) then
		
			result:AddInventory( "Command Armor", 6, 6 );
		
		end
		
		result:Give( "flechette_gun" )
		
		result:GetTable().HelmetHealth = 100;
		result:GetTable().BodyArmorHealth = 100;
		result:GetTable().SuperResistantArmor = true;
		result:GetTable().SuperResistantHelmet = true;
		
		
			TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") made you a Hunter" )
		Console( ply, "Made " .. result:GetRPName() .. " a hunter", true );
		
	end
	
end )

TS.AdminConsoleCommand( "rpa_stalker", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_stalker <Name> - Make player a stalker" );
		return;
	end

	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		result:SetModel( "models/stalker.mdl" )
		result:SetTeam( 4 )
		result:SetField( "radiofreq", TS.CombineRadioFreq )
		
		if( not result:HasInventory( "Command Armor" ) ) then
		
			result:AddInventory( "Command Armor", 6, 6 );
		
		end
		
		result:GetTable().HelmetHealth = 100;
		result:GetTable().BodyArmorHealth = 100;
		result:GetTable().SuperResistantArmor = false;
		result:GetTable().SuperResistantHelmet = false;
		
		
			TS.CreateRedNotify( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") made you a Stalker " )
		Console( ply, "Made " .. result:GetRPName() .. " a stalker", true );
		
	end
	
end )


TS.AdminConsoleCommand( "rpa_observe", false, function( ply, cmd, arg )

	if( ply:GetTable().ObserveMode ) then
	
		ply:Observe( false );
	
	else
	
		ply:Observe( true );
	
	end

end )


TS.AdminConsoleCommand( "rpa_noclip", false, function( ply, cmd, arg )
	
	if( ply:GetTable().NoclipMode ) then
	
		ply:Noclip( false );
	
	else
	
		ply:Noclip( true );
	
	end

end )


TS.AdminConsoleCommand( "rpa_team", false, function( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_team <Name> <Team Number> - Set player to a team" );
		return;
	end
	
	
	
	local name = arg[1];
	local team = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		result:SetTeam( team );
		result:Die();
		
	end


end )



TS.AdminConsoleCommand( "rpa_invishtml", false, function( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_invishtml <Link> - Open this link to everyone.  Don't include the http:// prefix." );
		return;
	end
	
	local link = arg[1];
	
	umsg.Start( "IHTML" );
		umsg.String( link );
	umsg.End();


end )



TS.AdminConsoleCommand( "rpa_plyrg", false, function( ply, cmd, arg )

	local name = arg[1]
	local status = arg[2] or ""
	
	local succ, result = TS.FindPlayerByName( name )
	TS.ErrorMessage( ply, false, succ, result )
	
	if( succ ) then
	
		result:CreateOtherRagDoll( result:GetRPName(), result:GetModel(), result:EyeAngles(), result:GetPos(), status )
		
		result:Kill()
		
	end

end )


TS.AdminConsoleCommand( "rpa_slap", false, function( ply, cmd, arg )
 
        local name = arg[1];
        local succ, result = TS.FindPlayerByName( name );
        TS.ErrorMessage( ply, false, succ, result );
        
        if( succ ) then
        
                TS.PrintMessageAll( 3, ply:GetRPName() .. " slapped " .. result:GetRPName() );
        
                local norm = result:GetAngles():Up();
                
                result:SetVelocity( norm * 500 + result:GetAngles():Forward() * math.random( -1000, 1000 ) );
                result:SetHealth( math.Clamp( result:Health() - 5, 1, 1000 ) );
        
        end
 
end )
 
TS.AdminConsoleCommand( "rpa_deflag", false, function( ply, cmd, arg )
 
        if( not arg[1] ) then 
                Console( ply, "rpa_deflag <Name> - Remove a players Combine Flags" );
                return;
        end
 
        
        local name = arg[1];
        
        local succ, result = TS.FindPlayerByName( name );
        TS.ErrorMessage( ply, false, succ, result );
        
        if( succ ) then
        
        if( result:NotFlagged() ) then
        
        Console( ply, result:GetRPName() .. " is not flagged.", true );
        
        else
                
                result:SetField( "combineflags", "" );
 
                Console( result, ply:GetRPName() .. "(" .. ply:SteamID() .. ") has removed your Combine flags.", true );
                Console( ply, "Removed " .. result:GetRPName() .. "'s flags.", true );
                
                        
                result:RefreshShit();
                result:KillSilent();
                result:Spawn();
                result:SaveData( "combineflags", result:GetField( "combineflags" ) );
                result:SetField( "radiofreq", 0 )
                
                local query = "UPDATE `characters` SET `CombineFlags` = '" .. " " .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";        
                
                sql.Query( query )
 
        end
        
        end
        
end )

CurrentFlags = {

	{ "C", "Combine" },
	{ "D", "OverWatch" },
	{ "B", "City Admin" },
	{ "V", "Vort" },
	{ "S", "Synths" },
	{ "M", "Misc" },
	
}	
 
TS.AdminConsoleCommand( "rpa_whitelist", false, function( ply, cmd, arg )
		
	if( !arg[1] or !arg[2] ) then
		Console( ply, "rpa_whitelist <name> <flag> - Flag a player for a faction" );
		return;
	end

	local name = arg[1];
	
	local factionname;
	
	--[[for k, v in pairs( CurrentFlags ) do
		if( arg[2] == v[1] and not string.len( arg[2] ) > 1 ) then
			factionname = " as " .. v[2];	
		end
	end	--]]
	
    local succ, result = TS.FindPlayerByName( name );
    TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		result:SetNWString( "Flags", result:GetNWString( "Flags" ) .. arg[2] );
		
		TS.PrintMessageAll( 3, ply:GetRPName() .. "[" .. ply:SteamID() .. "] whitelisted " .. result:GetRPName() .. " for a faction" );
		
		local query = "UPDATE `users` SET `PlayerFlags` = '" .. arg[2] .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'";           
        sql.Query( query )
		
	end	
        
end )

TS.AdminConsoleCommand( "rpa_blacklist", false, function( ply, cmd, arg )

	if( !arg[1] or !arg[2] ) then
		Console( ply, "rpa_blacklist <name> <flag> - Remove a player from a faction" );
		return;
	end
	
	local succ, result = TS.FindPlayerByName( name );
    TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		result:SetNWString( "Flags", result:GetNWString( "Flags" ) .. arg[2] );
		
		TS.PrintMessageAll( 3, ply:GetRPName() .. "[" .. ply:SteamID() .. "] blacksited " .. result:GetRPName() .. " from a faction" );
		
		local query = "UPDATE `users` SET `PlayerFlags` = '" .. " " .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'";           
        sql.Query( query )
		
	end	
        
end )

TS.AdminConsoleCommand( "rpa_charflag", false, function( ply, cmd, arg )

	if( not arg[1] or not arg[2] ) then
		return;
	end

	local name = arg[1];
	local flag = arg[2];

	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result )
	
	if( succ ) then
	
		result:SetPlayerCharacterFlags( flag )
		
		TS.CreateRedNotify( result, ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your character flag to " .. arg[2] .. "." );
		Console( ply, "Set " .. result:GetRPName() .. "'s character flag to " .. arg[2] .. ".", true );
		
		local query = "UPDATE `characters` SET `CharFlags` = '" .. arg[2] .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'";      
                
        sql.Query( query )
		
	end	
        
end )

TS.AdminConsoleCommand( "rpa_ban", false, function( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_ban <Name> <Time> <Reason> - Ban name for time minutes with reason" );
		return;
	end
	
	if( ply:EntIndex() ~= 0 or not ply:IsAdmin() ) then return; end
	
	local msg = "";
	
	if( arg[3] ) then
	
		for n = 3, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end
	
	
	local name = arg[1];
	local time = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:Ban( time, msg, ply:GetRPName() );
	
	end
	
end )	

 
TS.AdminConsoleCommand( "rpa_createitem", false, function( ply, cmd, arg )
 
        if( not arg[1] ) then return; end
        
        if( arg[1] == "ts2_kanyewest" and not ply:SteamID() == "STEAM_0:1:17476605" ) then
            ply:PrintMessage( 3, "How about NO" );
        end
        
        if( not TS.ItemsData[arg[1]] ) then return; end
        
        local trace = { }
        trace.start = ply:EyePos();
        trace.endpos = trace.start + ply:GetAimVector() * 150;
        trace.filter = ply;
        
        local tr = util.TraceLine( trace );
        
        TS.CreateItemProp( arg[1], tr.HitPos );
 
end )